<%@ include file="/WEB-INF/jsp/include.jsp"%>

 <c:url var="form_add_role" value="/admin/role/formAdd" />
 
<a href="${form_add_role}" class="btn btn-primary"><i class="icon-plus icon-white"></i>
    Add role</a>


<table class="table table-hover table-condensed">
	<caption>List of Roles</caption>
	<thead>
		<tr>
			<th>#</th>
			<th>Role</th>
			<th>Status</th>
			<th>Actions</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach var="role" items="${roles}">
             <c:choose>
                <c:when test="${role.enabled == false }">
                    <c:set var="disabled" value="error" />
                 </c:when>
                <c:otherwise>
                    <c:set var="disabled" value="" />
                </c:otherwise>
            </c:choose>
            
            <c:url var="delete_url" value="/admin/roles/delete/${role.id}" />
            <c:url var="lock_url" value="/admin/roles/block/${role.id}" />
            <c:url var="unlock_url" value="/admin/roles/unblock/${role.id}" />            

            <tr class="${disabled}">
                <td>${role.id}</td>
                <td>${role.name}</td>
                <td>${role.enabled}</td>
                <td>
                    <c:if test="${role.name != 'ROLE_ADMIN'}">
                        <c:choose>
                            <c:when test="${role.enabled == false }">
                                <a href="${unlock_url}"><i class="icon-thumbs-up"></i></a> 
                         </c:when>
                            <c:otherwise>
                                <a href="${lock_url}"><i class="icon-lock"></i></a> 
                            </c:otherwise>
                        </c:choose>
                        <a href="${delete_url}"><i class="icon-trash"></i></a>
                     </c:if>
                    
                </td>
            </tr>
        </c:forEach>
	</tbody>
</table>

<c:url var="firstUrl" value="/admin/roles/pages/1" />
<c:url var="lastUrl" value="/admin/roles/pages/${totalPages}" />
<c:url var="prevUrl" value="/admin/roles/pages/${currentIndex - 1}" />
<c:url var="nextUrl" value="/admin/roles/pages/${currentIndex + 1}" />

<div class="pagination">
    <ul>
        <c:choose>
            <c:when test="${currentIndex == 1}">
                <li class="disabled"><a href="#">&lt;&lt;</a></li>
                <li class="disabled"><a href="#">&lt;</a></li>
            </c:when>
            <c:otherwise>
                <li><a href="${firstUrl}">&lt;&lt;</a></li>
                <li><a href="${prevUrl}">&lt;</a></li>
            </c:otherwise>
        </c:choose>
        <c:forEach var="i" begin="${beginIndex}" end="${endIndex}">
            <c:url var="pageUrl" value="/admin/roles/pages/${i}" />
            <c:choose>
                <c:when test="${i == currentIndex}">
                    <li class="active"><a href="${pageUrl}"><c:out value="${i}" /></a></li>
                </c:when>
                <c:otherwise>
                    <li><a href="${pageUrl}"><c:out value="${i}" /></a></li>
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <c:choose>
            <c:when test="${currentIndex == totalPages}">
                <li class="disabled"><a href="#">&gt;</a></li>
                <li class="disabled"><a href="#">&gt;&gt;</a></li>
            </c:when>
            <c:otherwise>
                <li><a href="${nextUrl}">&gt;</a></li>
                <li><a href="${lastUrl}">&gt;&gt;</a></li>
            </c:otherwise>
        </c:choose>
    </ul>
</div>
